package com.uzai.console.web.sys;

import com.google.common.collect.Lists;
import com.uzai.common.exception.BusinessException;
import com.uzai.console.dto.SysRoleSettingDto;
import com.uzai.console.service.sysrole.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * @author mingyang.chen create in 2023/6/20 10:59
 */
@RestController
@RequestMapping("/roleSetting")
@Api(value = "子账号角色设置接口管理", tags = "子账号角色设置")
public class SysRoleSettingController {

    @Autowired
    private SysRoleService sysRoleService;

    private final List<Long> ids = Lists.newArrayList(1498562928796880897L, 1157181383497326594L);

    @PostMapping("/save")
    @ApiOperation(value = "保存角色配置", notes = "保存角色配置")
    public Object setting(@RequestBody SysRoleSettingDto settingDto) {

        if (Objects.isNull(settingDto) || StringUtils.isBlank(settingDto.getSettingJson())) {
            throw new BusinessException("参数错误");
        }
        if (!ids.contains(settingDto.getMerId())) {
            throw new BusinessException("无权操作");
        }
        sysRoleService.setChildAccountRole(settingDto.getSettingJson());
        return true;
    }
}
